<template>
  <div class="my">
    <div class="top">
      <div class="top-info">
        <div class="left">
          <div class="left-title">{{ userInfo.nickname }}</div>
          <div class="left-txt">{{ userInfo.intro }}</div>
        </div>
        <img
          v-if="userInfo.avatar"
          :src="baseUrl + userInfo.avatar"
          alt=""
          class="right"
          @click="goInfo"
        />
        <img
          v-else
          src="@/assets/logo.png"
          alt=""
          class="right"
          @click="goInfo"
        />
      </div>
      <ul class="top-num">
        <li class="top-num-item">
          <div class="num">298</div>
          <div class="txt">累计答题</div>
        </li>
        <li class="top-num-item">
          <div class="num">298</div>
          <div class="txt">累计答题</div>
        </li>
        <li class="top-num-item">
          <div class="num">298</div>
          <div class="txt">累计答题</div>
        </li>
        <li class="top-num-item">
          <div class="num">298</div>
          <div class="txt">累计答题</div>
        </li>
      </ul>
      <div
        class="top-card"
        @click="$router.push('/home/editInfo?type=position')"
      >
        <!-- 单元格 -->
        <my-cell
          title="我的岗位"
          :value="userInfo.position"
          icon="&#xe64d;"
        ></my-cell>
      </div>
    </div>
    <div class="content">
      <div class="middle">
        <h3 class="middle-title">面经数据</h3>
        <ul class="middle-num">
          <li class="middle-num-item">
            <div class="item-one">昨日阅读<span class="color">+666</span></div>
            <div class="item-two">17</div>
            <div class="item-three">阅读总数</div>
          </li>
          <li class="middle-num-item">
            <div class="item-one">昨日获赞<span class="color">+999</span></div>
            <div class="item-two">297</div>
            <div class="item-three">获赞总数</div>
          </li>
          <li class="middle-num-item">
            <div class="item-one">昨日新增<span class="color">+888</span></div>
            <div class="item-two">187</div>
            <div class="item-three">评论总数</div>
          </li>
        </ul>
      </div>
      <div class="bottom">
        <my-cell
          class="cell"
          icon="&#xe655;"
          title="我的面经分享"
          value="21"
        ></my-cell>
        <my-cell
          class="cell"
          icon="&#xe656;"
          title="我的消息"
          value="98"
        ></my-cell>
        <my-cell
          class="cell"
          icon="&#xe654;"
          title="收藏的题库"
          value="32"
        ></my-cell>
        <my-cell
          class="cell"
          icon="&#xe648;"
          title="收藏的企业"
          value="32"
        ></my-cell>
        <my-cell
          class="cell"
          icon="&#xe64f;"
          title="我的错题"
          value="123"
        ></my-cell>
        <my-cell
          class="cell"
          icon="&#xe611;"
          title="收藏的面试经验"
          value="166"
        ></my-cell>
      </div>
    </div>
  </div>
</template>

<script>
import myCell from './myCell'
import { mapState } from 'vuex'
// import { auInfo } from '@/api/my.js'
// import { getLocal } from '@/utils/local'
export default {
  data () {
    return {
      baseUrl: process.env.VUE_APP_URL
    }
  },
  components: {
    myCell
  },
  // 计算属性拿到vuex中的值
  computed: {
    ...mapState(['userInfo', 'isLogin'])
  },
  created () {
    /**
     * 1.如果登录了
     *    就不去理会
     * 2.如果没有登录
     *    判断有没有token 有token
     *        调用获取用户信息接口并保存数据
     *    没有token
     *       跳转到登录页
     */
    //  if (!this.isLogin) {
    //    if (getLocal) {
    //      auInfo()
    //        .then(res => {
    //          // console.log(res)
    //          // 保存用户信息
    //          this.$store.commit('setUserInfo', res.data.data)
    //          // 判断是否登录
    //          this.$store.commit('setIsLogin', true)
    //        })
    //        .catch(err => {
    //          window.console.log(err)
    //        })
    //    } else {
    //      this.$router.push('/login')
    //    }
    //  }
  },
  methods: {
    // 点击头头像跳转到个人详情页
    goInfo () {
      this.$router.push('/home/myInfo')
    }
  },
  mounted () {
    // 解决背景色问题:进入页面时设置body的背景色
    document.body.style.backgroundColor = '#f7f4f5'
  },
  beforeDestroy () {
    // 离开时恢复背景色
    document.body.style.backgroundColor = '#fff'
  }
}
</script>
<style lang="less">
.my {
  .top {
    padding: 31px @p15 55px;
    background: linear-gradient(45deg, #ce0031, #b8002c);
    position: relative;
    .top-info {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .left {
        .left-title {
          font-size: 21px;
          font-family: PingFangSC, PingFangSC-Semibold;
          font-weight: 600;
          text-align: left;
          color: #ffffff;
          line-height: 28px;
          letter-spacing: 0px;
        }
        .left-txt {
          opacity: 0.7;
          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          text-align: left;
          color: #ffffff;
          line-height: 16px;
          letter-spacing: 0px;
        }
      }
      .right {
        width: 50px;
        height: 50px;
        border: 3px solid rgba(255, 255, 255, 0.38);
        border-radius: 50%;
      }
    }
    .top-num {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 31px;
      .top-num-item {
        text-align: center;
        .num {
          font-size: 18px;
          font-family: DINAlternate, DINAlternate-Bold;
          font-weight: 700;
          text-align: center;
          color: #ffffff;
          line-height: 24px;
          letter-spacing: 0px;
        }
        .txt {
          opacity: 0.7;
          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          text-align: left;
          color: #ffffff;
          line-height: 16px;
          letter-spacing: 0px;
        }
      }
    }
    .top-card {
      position: absolute;
      left: 0;
      bottom: -16px;
      width: 100%;
      padding: 0 @p15;
      .cell {
        border-radius: 5px;
      }
    }
  }
  .content {
    background-color: #f7f4f5;
    padding: 26px @p15;
    .middle {
      background-color: #fff;
      padding: 19px 15px;
      border-radius: 3px;
      .middle-title {
        font-size: 16px;
        font-family: PingFangSC, PingFangSC-Semibold;
        font-weight: 700;
        text-align: left;
        color: #181a39;
        line-height: 20px;
        letter-spacing: 0px;
      }
      .middle-num {
        display: flex;
        justify-content: space-around;
        text-align: center;
        margin-top: 17px;
        .middle-num-item {
          .item-one {
            font-size: 12px;
            font-family: PingFangSC, PingFangSC-Regular;
            font-weight: 400;
            text-align: center;
            color: #b4b4bd;
            line-height: 14px;
            letter-spacing: 0px;
            .color {
              color: #00b8d4;
            }
          }
          .item-two {
            font-size: 21px;
            font-family: DINAlternate, DINAlternate-Bold;
            font-weight: 700;
            text-align: center;
            color: #181a39;
            line-height: 24px;
            letter-spacing: 0px;
            padding: 10px 0;
          }
          .item-three {
            font-size: 12px;
            font-family: PingFangSC, PingFangSC-Regular;
            font-weight: 400;
            text-align: center;
            color: #545671;
            line-height: 16px;
            letter-spacing: 0px;
          }
        }
      }
    }
    .bottom {
      margin-top: 10px;
      border-radius: 3px;
    }
  }
}
</style>
